// 楼栋相关API接口和mock数据

// Mock数据
const mockBuildingInfo = {
  buildingInfo: {
    name: '1号楼',
    description: '学生公寓楼',
    residents: 120,
    floors: 6
  },
  recentActivities: [
    {
      id: 1,
      title: '跑腿订单已完成',
      time: '2分钟前',
      icon: 'checkmark-circle',
      color: '#19be6b',
      status: '已完成',
      statusType: 'success'
    },
    {
      id: 2,
      title: '超市订单配送中',
      time: '10分钟前',
      icon: 'car',
      color: '#ff9900',
      status: '配送中',
      statusType: 'warning'
    },
    {
      id: 3,
      title: '维修申请已受理',
      time: '1小时前',
      icon: 'tools',
      color: '#2979ff',
      status: '处理中',
      statusType: 'primary'
    }
  ],
  buildingNotice: {
    content: '各位住户请注意，本周六将进行电梯维护，请合理安排出行时间。',
    time: '2024-01-15 10:30'
  }
}

const mockRunServices = {
  services: [
    {
      id: 1,
      name: '食堂打包',
      description: '食堂饭菜打包配送',
      price: 5,
      deliveryTime: 15,
      category: 'food',
      image: '/static/images/food.png'
    },
    {
      id: 2,
      name: '快递代取',
      description: '快递点代取包裹',
      price: 3,
      deliveryTime: 20,
      category: 'express',
      image: '/static/images/express.png'
    },
    {
      id: 3,
      name: '超市代购',
      description: '生活用品代购',
      price: 8,
      deliveryTime: 30,
      category: 'daily',
      image: '/static/images/supermarket.png'
    },
    {
      id: 4,
      name: '打印服务',
      description: '文档打印配送',
      price: 2,
      deliveryTime: 10,
      category: 'other',
      image: '/static/images/print.png'
    },
    {
      id: 5,
      name: '外卖代取',
      description: '外卖配送服务',
      price: 4,
      deliveryTime: 12,
      category: 'food',
      image: '/static/images/takeout.png'
    },
    {
      id: 6,
      name: '药品代购',
      description: '常用药品代购',
      price: 10,
      deliveryTime: 25,
      category: 'other',
      image: '/static/images/medicine.png'
    }
  ]
}

const mockSupermarketProducts = {
  products: [
    {
      id: 1,
      name: '方便面',
      description: '康师傅红烧牛肉面',
      price: 4.5,
      stock: 50,
      category: 'food',
      image: '/static/images/noodles.png'
    },
    {
      id: 2,
      name: '矿泉水',
      description: '农夫山泉550ml',
      price: 2,
      stock: 100,
      category: 'drink',
      image: '/static/images/water.png'
    },
    {
      id: 3,
      name: '牙膏',
      description: '云南白药牙膏',
      price: 15,
      stock: 30,
      category: 'daily',
      image: '/static/images/toothpaste.png'
    },
    {
      id: 4,
      name: '薯片',
      description: '乐事薯片原味',
      price: 8,
      stock: 25,
      category: 'snack',
      image: '/static/images/chips.png'
    },
    {
      id: 5,
      name: '苹果',
      description: '新鲜红富士苹果',
      price: 12,
      stock: 20,
      category: 'fresh',
      image: '/static/images/apple.png'
    },
    {
      id: 6,
      name: '牛奶',
      description: '蒙牛纯牛奶250ml',
      price: 6,
      stock: 40,
      category: 'drink',
      image: '/static/images/milk.png'
    },
    {
      id: 7,
      name: '面包',
      description: '全麦面包',
      price: 8,
      stock: 15,
      category: 'food',
      image: '/static/images/bread.png'
    },
    {
      id: 8,
      name: '洗发水',
      description: '海飞丝洗发水',
      price: 25,
      stock: 20,
      category: 'daily',
      image: '/static/images/shampoo.png'
    }
  ]
}

// API接口函数
export const buildingAPI = {
  // 获取楼栋信息
  async getBuildingInfo() {
    try {
      // 模拟API调用延迟
      await new Promise(resolve => setTimeout(resolve, 500))
      
      return {
        code: 200,
        message: 'success',
        data: mockBuildingInfo
      }
    } catch (error) {
      throw new Error('获取楼栋信息失败')
    }
  },

  // 获取跑腿服务列表
  async getRunServices() {
    try {
      await new Promise(resolve => setTimeout(resolve, 300))
      
      return {
        code: 200,
        message: 'success',
        data: mockRunServices
      }
    } catch (error) {
      throw new Error('获取跑腿服务失败')
    }
  },

  // 获取超市商品列表
  async getSupermarketProducts() {
    try {
      await new Promise(resolve => setTimeout(resolve, 400))
      
      return {
        code: 200,
        message: 'success',
        data: mockSupermarketProducts
      }
    } catch (error) {
      throw new Error('获取超市商品失败')
    }
  },

  // 提交跑腿订单
  async submitRunOrder(orderData) {
    try {
      await new Promise(resolve => setTimeout(resolve, 800))
      
      // 模拟订单ID生成
      const orderId = Date.now().toString()
      
      return {
        code: 200,
        message: '订单提交成功',
        data: {
          orderId,
          orderData
        }
      }
    } catch (error) {
      throw new Error('提交订单失败')
    }
  },

  // 提交超市订单
  async submitSupermarketOrder(orderData) {
    try {
      await new Promise(resolve => setTimeout(resolve, 600))
      
      const orderId = Date.now().toString()
      
      return {
        code: 200,
        message: '订单提交成功',
        data: {
          orderId,
          orderData
        }
      }
    } catch (error) {
      throw new Error('提交订单失败')
    }
  },

  // 获取订单列表
  async getOrderList(userId, status = 'all') {
    try {
      await new Promise(resolve => setTimeout(resolve, 500))
      
      const mockOrders = [
        {
          id: '1',
          type: 'run',
          title: '跑腿订单',
          status: 'completed',
          amount: 15,
          createTime: '2024-01-15 14:30',
          items: [
            { name: '食堂打包', quantity: 1, price: 5 },
            { name: '快递代取', quantity: 2, price: 3 }
          ]
        },
        {
          id: '2',
          type: 'supermarket',
          title: '超市订单',
          status: 'delivering',
          amount: 25.5,
          createTime: '2024-01-15 13:20',
          items: [
            { name: '方便面', quantity: 2, price: 4.5 },
            { name: '矿泉水', quantity: 3, price: 2 },
            { name: '牙膏', quantity: 1, price: 15 }
          ]
        }
      ]
      
      let filteredOrders = mockOrders
      if (status !== 'all') {
        filteredOrders = mockOrders.filter(order => order.status === status)
      }
      
      return {
        code: 200,
        message: 'success',
        data: {
          orders: filteredOrders
        }
      }
    } catch (error) {
      throw new Error('获取订单列表失败')
    }
  },

  // 获取订单详情
  async getOrderDetail(orderId) {
    try {
      await new Promise(resolve => setTimeout(resolve, 300))
      
      const mockOrderDetail = {
        id: orderId,
        type: 'run',
        title: '跑腿订单',
        status: 'completed',
        amount: 15,
        createTime: '2024-01-15 14:30',
        deliveryTime: '2024-01-15 15:00',
        items: [
          { name: '食堂打包', quantity: 1, price: 5 },
          { name: '快递代取', quantity: 2, price: 3 }
        ],
        deliveryAddress: '1号楼101室',
        contactPhone: '13800138000',
        remark: '请尽快配送'
      }
      
      return {
        code: 200,
        message: 'success',
        data: mockOrderDetail
      }
    } catch (error) {
      throw new Error('获取订单详情失败')
    }
  },

  // 取消订单
  async cancelOrder(orderId) {
    try {
      await new Promise(resolve => setTimeout(resolve, 500))
      
      return {
        code: 200,
        message: '订单取消成功',
        data: { orderId }
      }
    } catch (error) {
      throw new Error('取消订单失败')
    }
  },

  // 确认收货
  async confirmOrder(orderId) {
    try {
      await new Promise(resolve => setTimeout(resolve, 500))
      
      return {
        code: 200,
        message: '确认收货成功',
        data: { orderId }
      }
    } catch (error) {
      throw new Error('确认收货失败')
    }
  }
}

// 导出默认对象
export default buildingAPI 